<?php
/* @var $this ShiftChangeController */
/* @var $model ShiftChange */
$this->pageTitle=Yii::app()->name . ' - Temporal Shift Change';

//date processing
$dateArray = explode('-',$model->day_requested);
$dateObject = new DateTime('NOW');
$dateObject->setTimeZone(new DateTimeZone("America/Costa_Rica"));
$dateObject->setDate($dateArray[0],$dateArray[1],$dateArray[2]);
$week= $dateObject->format('W');
$year= $dateObject->format('o');

$this->breadcrumbs=array(
	'Management'=>array('/site/management/'),
	'Roster Control'=>array('roster/index', 'week'=>$week, 'year'=>$year),
	'Temporal Shift Change',
);

$this->menu=array(
	//array('label'=>'List ShiftChange', 'url'=>array('index')),
	array('label'=>'Return to Roster Control', 'url'=>array('roster/index', 'week'=>$week, 'year'=>$year)),
);

$cs = Yii::app()->getClientScript();  
$cs->registerScript(
  'radio-type-handler',
  '
	function radioToggle(){
		var r1selected= document.getElementById("choice_0").checked;
		var r2selected= document.getElementById("choice_1").checked;
		
		//alert("r1selected= " + r1selected);
		//alert("r2selected= " + r2selected);
		
		if (r1selected) {
			document.getElementById("ShiftChange_requested_shift").style.visibility = "visible";
			document.getElementById("ShiftChange_requested_qshift").style.visibility = "visible";
			document.getElementById("ShiftChange_target_user").style.visibility = "hidden";
			document.getElementById("txt_target_shift").style.visibility = "hidden";
			document.getElementById("txt_target_qshift").style.visibility = "hidden";
		} else if (r2selected) {
			document.getElementById("ShiftChange_requested_shift").style.visibility = "hidden";
			document.getElementById("ShiftChange_requested_qshift").style.visibility = "hidden";
			document.getElementById("ShiftChange_target_user").style.visibility = "visible";
			document.getElementById("txt_target_shift").style.visibility = "visible";
			document.getElementById("txt_target_qshift").style.visibility = "visible";
		}
	}
	
	function setRequestedShiftQshift(shift, qshift){
	
		//alert("shift= " + shift + " qshift= " +qshift);

		var shiftOptions = document.getElementById("ShiftChange_requested_shift").options;
		var qshiftOptions = document.getElementById("ShiftChange_requested_qshift").options;
		var shiftIndexPos = 0;
		var qshiftIndexPos = 0;
		
		for (var i=0; i < shiftOptions.length ; i++) {
			if (shiftOptions[i].value == shift) {
				shiftIndexPos = i;	
			}	//alert("shift i = " + i);
		}		
		
		for (var j=0; j < qshiftOptions.length ; j++) {
			if (qshiftOptions[j].value == qshift){
				qshiftIndexPos = j;		
			}	//alert("qshift j = " + j);				
		}
		
		document.getElementById("ShiftChange_requested_shift").selectedIndex = shiftIndexPos;
		document.getElementById("ShiftChange_requested_qshift").selectedIndex = qshiftIndexPos;
	
	}
	
	function cleanDropdown(dropdownId) {
	
		document.getElementById(dropdownId).selectedIndex = 0;
	}
  ',
  CClientScript::POS_END
);
?>

<h2>Temporal Shift Change for <?php echo User::model()->findByPk($model->requesting_user)->fullname; ?> </h2>
<br>


<?php //echo $this->renderPartial('_rosterCreate_form', array('model'=>$model),false,true); ?>

<div class="form" style="width:420px;">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'shift-change-form',
	'enableAjaxValidation'=>false,
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,)			
)); ?>

<center>
	<p class="note">Fields with <span class="required">*</span> are required.</p>
	<?php echo $form->errorSummary($model); ?>

<br>
	<div class="row">
		<?php
		echo CHtml::textField( 'date',$model->day_requested ,array('size'=>9,'readonly'=>true,'id'=>'ShiftChange_day_requested')) ;
		?>
	</div>
<p>
<table style="width:350px;">

	<tr >
		<td  >
			<center>
			<center>
			<div class="row compactRadioGroup">
			<?php echo CHtml::radioButtonList('choice',
											  'radioToShift',
											  array('radioToShift'=>'Direct Change'),
											  array('separator' => '&nbsp&nbsp&nbsp|&nbsp&nbsp&nbsp&nbsp',
													)
											  ); ?>
			</div>
			</center>
		</td>
	</tr>
	
	<tr>
		<td >
		<center>
		
		<div class="row">
				<?php echo $form->labelEx($model,'requested_shift'); ?>
					<?php echo $form->dropDownList($model,'requested_shift',
												   CHtml::listData(Shift::model()->findAll(array('condition'=>'team_id = '.$model->team_id.' and enabled = 1', 'order'=>'start_time ASC')),
																   'idshift', 
																   'name',
																   'start_time'),	
													array('empty'=>'','class'=>'dropshift','style'=>'visibility:visible;'));?>
				<?php echo $form->error($model,'requested_shift'); ?>
			</div>

			<div class="row" >
				<?php echo $form->labelEx($model,'requested_qshift'); ?>
					<?php echo $form->dropDownList($model,'requested_qshift',
												   CHtml::listData(Qshift::model()->findAll(array('condition'=>'team_id = '.$model->team_id.' and enabled = 1', 'order'=>'start_time ASC')),
																   'idqshift', 
																   'name'),	
													array('empty'=>'','class'=>'dropshift','style'=>'visibility:visible;'));?>		
				<?php echo $form->error($model,'requested_qshift'); ?>
			</div>
		</center>
		</td>
		

	</tr>
</table>

	<div class="row">
		<?php echo $form->labelEx($model,'comments'); ?>
		<?php echo $form->textArea($model,'comments',array('row'=>2,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'comments'); ?>
	</div>
	
<br>
	<div class="buttons">
		<?php echo CHtml::submitButton('Create'); ?>
								
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

